package com.lailai.controller;

import com.lailai.constant.ErrorCode;
import com.lailai.domainservice.response.SingleResponse;
import com.lailai.exception.BusinessException;
import com.lailai.service.TestService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author lgr
 * @Date 2025/9/18
 * @Email 983105834@qq.com
 */
@RestController
@RequestMapping("/api")
public class TestController {
    private static final Logger logger = LoggerFactory.getLogger(RouterController.class);

    @Autowired
    private TestService testService;

    @GetMapping("/test")
    public SingleResponse<List<String>> testApi() {
        try {
            List<String> list = testService.test();
            return SingleResponse.of(list);
        } catch (BusinessException e) {
            logger.error("业务异常", e);
            return SingleResponse.ofFailure(String.valueOf(e.getCode()), e.getMessage());
        } catch (Exception e) {
            logger.error("系统异常", e);
            return SingleResponse.ofFailure(
                    String.valueOf(ErrorCode.SYSTEM_ERROR.getCode()),
                    "系统内部错误: " + e.getMessage()
            );
        }
    }
}
